import { obj_int, uJob, d_sort, cline } from 'sui';
import { load_supply } from '../task/cmd';

const load_sale = (hDone, setMain) => {
    uJob(hDone, "sale/listback", { line: cline() },
        r => {
            d_sort(r, "sn");

            r.forEach((d, i) => {
                d["index"] = i + 1;

                const v = d.v;
                if (v) {
                    let num = 0;
                    v.forEach(d => num += obj_int(d, "num"));
                    d["num"] = num;
                }
            });

            setMain(r);
        },
        e => setMain(null));
};

const load_ng = (setMain, mapStuff) => load_supply(setMain, mapStuff, "ng", "ngp");

export {load_ng, load_sale};
